package com.example.demo.config;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 * User:xieChao
 * Date:2022/12/24 19:21
 */
//统一异常的拦截处理类
    @RestControllerAdvice
public class MyExceptionAdvice {
        @ExceptionHandler(Exception.class)
    public Object exceptionAdvice(Exception e){
            HashMap<String,Object> result = new HashMap<>();
            result.put("state",-1);
            result.put("msg","程序异常" + e.getMessage());
            result.put("data","");
            return result;
        }
}
